import { server } from '../config/server';
import { useToken } from '../utils/token';

export const file = {
    /*
     * 获取文件预签名URL
     */
    downloadPublicFile(fileId) {
        return new Promise((resolve, reject) => {
            let jwt = wx.getStorageSync('loginToken');
            wx.request({
                url: `${server.server_addr}/file/downloadPublicFile`,
                method: 'POST',
                header: {
                    'Authorization': jwt,               // 假设使用 JWT 作为授权头
                    'Content-Type': 'application/json'  // 根据实际情况调整
                },
                data: { fileId },
                success: (res) => {
                    console.log('【 Response in request downloadPublicFile 】', res);
                    resolve(res.data);
                    useToken(res);
                },
                fail: (err) => {
                    console.log('【 Error in request downloadPublicFile 】', err);
                    reject({ success: false, err });
                }
            });
        });
    }
};